package love.yuanmengrobot.guoyitang.service.impl;
/*
 *   @Studio:CHJY · 源梦科技
 *   @Author:COOLIGHT
 *   @Ide:IntelliJ IDEA
 *   @Creation time:2021/8/11 0011 11:41
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import love.yuanmengrobot.guoyitang.entity.TbNatmehaDoctor;
import love.yuanmengrobot.guoyitang.entity.TbNatmehaHospital;
import love.yuanmengrobot.guoyitang.entity.TbNatmehaRegisterRef;
import love.yuanmengrobot.guoyitang.mapper.TbNatmehaDoctorMapper;
import love.yuanmengrobot.guoyitang.mapper.TbNatmehaHospitalMapper;
import love.yuanmengrobot.guoyitang.mapper.TbNatmehaRegisterRefMapper;
import love.yuanmengrobot.guoyitang.service.AppointmentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Random;

@Service
public class AppointmentServiceImpl implements AppointmentService {
    @Resource
    private TbNatmehaHospitalMapper hospitalMapper;

    @Resource
    private TbNatmehaDoctorMapper doctorMapper;

    @Resource
    private TbNatmehaRegisterRefMapper registerRefMapper;

    @Override
    public IPage<TbNatmehaHospital> findAllHospital(IPage<TbNatmehaHospital> page) {
        IPage<TbNatmehaHospital> hospitalIPage = hospitalMapper.selectPage(page, null);
        return hospitalIPage;
    }

    @Override
    public List<TbNatmehaDoctor> findAllDoctor(String org_code) {
        return doctorMapper.selectList(new QueryWrapper<TbNatmehaDoctor>().eq("org_code", org_code));
    }

    @Override
    public String addRegisterRef(TbNatmehaRegisterRef registerRef) {
        registerRef.setRegisterNum(new Random().nextInt(99) + 1);
        registerRef.setRegisterStatus("挂号成功");
        Date date = new Date();
        registerRef.setItemcreateat(date);
        registerRef.setItemupdateat(date);
        if (registerRefMapper.insert(registerRef) == 1) {
            return "SUCCESS";
        }
        return "FAILED";
    }
}
